@extends('layouts.header')
@section('title','检测设备')
@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 设备管理 <span class="c-gray en">&gt;</span>检测设备<a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray">
            <span class="">
                <a href="javascript:;" onclick="layer_show('添加','/{{config('constant.name_admin')}}/station/add?id=0')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加</a>
                <a href="" class="btn btn-primary radius" onclick="Export()">当前页导出xls</a>
            </span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg" id="datatable" style="white-space: nowrap;">
                <thead>
                <tr class="text-c">
                    {{-- <th width="25"><input type="checkbox" name="" value=""></th>
                    --}}
                    <th>序号</th>
                    <th>仪器设备名称</th>
                    <th>设备编号</th>
                    <th>出厂编号</th>
                    <th>规格/型号</th>
                    <th>量程范围</th>
                    <th>准确度/等级</th>
                    <th>溯源方式</th>
                    <th>溯源单位</th>
                    <th>溯源日期</th>
                    <th>有效截止日期至</th>
                    <th>校准周期</th>
                    <th>设备状态</th>
                    <th>负责人</th>
                    <th>生产厂家</th>
                    <th>购入日期</th>
                    <th>设备局域网IP</th>
                    <th>显示器局域网IP</th>
                    <th>创建日期</th>
                    <th>备注</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
    {{--    导出表格用--}}
    <script type="text/javascript" src="/admin/static/myfolder/js/jquerytable2excel.js"></script>
    <script type="text/javascript" src="/admin/static/myfolder/js/printBarCode.js?ver={{config('constant.static_res_ver')}}"></script>

    <script type="text/javascript">
        @php 
            $setting_info = DB::table('setting_sys')->where('key', 'print_bar_code')->value('value'); //设置信息
            $setting_info = json_decode($setting_info, true);
        @endphp
        var table, dataIndex = @json($data),is_remote_print = {{ isset($setting_info['is_remote']) ? $setting_info['is_remote'] : 0}},//为本机打印或远程打印(本机打印:0 , 远程打印:1)
            remote_ip='127.0.0.1';
        $(function () {
            $.fn.dataTable.ext.errMode = 'throw'; //datatable抛异常的方式，在console中输出，默认以alert的方式弹出
            table = $('#datatable').DataTable({
                // pageLength: 3,
                // dom: "it" +
                // "< 'row'p>",
                // lengthChange: !1,
                "scrollX": true,
                "deferRender": true, //延迟渲染速度
                "ordering": false, // 是否排序
                ajax: "/{{ config('constant.name_admin') }}/station/index",
                "processing": true, //加载数据时候是否显示进度条
                language: {
                    url: '/admin/lib/datatables/dataTables_Chinese_Lang.json'
                },
                columns: [
                    {data: null, class: "text-c num"},
                    {data: "name", class: "node-name"},
                    {data: "dev_num", defaultContent: '/'},
                    {data: "fac_num", defaultContent: '/'},
                    {data: "spec", defaultContent: '/'},
                    {data: 'ranges', defaultContent: '/'},
                    {data: "accuracy", defaultContent: '/'},
                    {
                        data: "trace_type", class: "text-c", render: function (data, type, row, meta) {
                            return dataIndex.trace_type[data];
                        }
                    },
                    {data: "trace_com", defaultContent: '/'},
                    {data: "trace_date", class: "text-c", defaultContent: '/'},
                    {data: "trace_exp_date", class: "text-c", defaultContent: '/'},
                    {
                        data: "trace_cycle", class: "text-c", render: function (data, type, row, meta) {
                            return dataIndex.trace_cycle[data];
                        }
                    },
                    {
                        data: "status", class: "text-c", render: function (data, type, row, meta) {
                            return dataIndex.status[data];
                        }
                    },
                    {data: "user", class: "text-c", defaultContent: '/'},
                    {data: "factory", defaultContent: '/'},
                    {data: "buy_date", class: "text-c", defaultContent: '/'},
                    {data: "dev_lan_ip", class: "text-c dev_lan_ip", defaultContent: '/'},
                    {data: "com_lan_ip", class: "text-c com_lan_ip", defaultContent: '/'},
                    {
                        data: "ctime", class: "text-c", defaultContent: '/', render: function (data, type, row, meta) {
                            return data.substring(0, 10);
                        }
                    },
                    {data: "remark", class: "text-c"},
                    {
                        data: null,
                        class: "text-c",
                        //操作
                        render: function (data, type, row, meta) {
                            console.log(row.dev_lan_ip);
                            let str = '<a class="ml-5 btn btn-primary-outline radius size-MINI" href="javascript:;" onclick="edit(\'修改\',\'/{{ config('constant.name_admin') }}/station/edit\',\'' + row.id + '\')">修改</a>' +
                                '<a onclick="del(' + row.id + ',this)" class="ml-5 btn btn-danger-outline radius size-MINI">删除</a>' +
                                '<a onclick="print_ip(this,\'dev_lan_ip\')" class="ml-5 btn btn-secondary-outline radius size-MINI ';
                                if(row.dev_lan_ip == ''){
                                    str += ' disabled ';
                                }
                                str += '" >打印设备IP</a>'+
                                '<a onclick="print_ip(this,\'com_lan_ip\')" class="ml-5 btn btn-secondary-outline radius size-MINI';
                                if(row.com_lan_ip == ''){
                                    str += ' disabled ';
                                }
                                str += '">打印显示器IP</a>'+
                                '<a onclick="pcshow(\'http://' + row.com_lan_ip + ':7000\')" class="ml-5 btn btn-secondary-outline radius size-MINI">显示器屏幕</a>';
                            return str;
                        }
                    }
                ],

            });
            table.on('draw', function (a, b) {
                let pageinfo = table.page.info();
                $(a.target.rows).each(function (index) {
                    $(this).find('td.num').text(pageinfo.start + index);
                    $('td').each(function () {
                        $(this).text() === '' ? $(this).text('/') : '';
                    });
                })
                table.columns.adjust();
            })
        });

        function Export() {
            $("#datatable").table2excel({            //exceltable为存放数据的table
                // 不被导出的表格行的CSS class类
                exclude: ".noExl",
                // 导出的Excel文档的名称
                name: "(云平台)设备管理台账",
                // Excel文件的名称
                filename: "(云平台)设备管理台账",
                bootstrap: true
            });
        }

        function pcshow(url) {
            $.ajax({
                type: "GET",
                cache: false,
                url: url,
                dataType: "jsonp",
                timeout: 2000,
                complete: function (res) {
                    res.status == 200 ? layer_show('主机屏幕', url) : '';
                }
            }).fail(function (jqXHR, textStatus, errorThrown) {
                // net::ERR_CONNECTION_REFUSED 发生时，也能进入
                layer.msg("主机未开启或未共享");
            });
        }

        /*重复输出一个字符串*/
        function str_repeat(string, times) {
            var res = "";
            for (var i = 0; i < times; i++) {
                res += string;
            }
            return res;
        }

        /*表格重新加载*/
        function table_reload(bool) {
            //清除表头 CheckBox的对勾
            $("#datatable").find("thead").find("input[type=checkbox]").removeAttr('checked');
            if (bool) {
                //true时，跳到第一页
                table.ajax.reload();
            } else {
                //false时，停留在原来页
                table.ajax.reload(null, false);
            }
        }

        /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
        */

        /*编辑*/
        function edit(title, url, id, w, h) {
            layer_show(title, url + '?id=' + id, w, h);
        }

        /*删除*/
        function del(id, obj) {
            var index2;
            var node_name = $(obj).closest('tr').find('td.node-name').text();
            layer.confirm('确认要删除“' + node_name + '”吗？', function (index) {
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/station/del' + '?id=' + id,
                    // dataType: 'json',
                    success: function (data) {
                        if (data === '1') {
                            table_reload(0); //0停留在当前页，1回到第一页
                            layer.msg('删除成功!', {
                                icon: 1,
                                time: 2000
                            });
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    },
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {
                            shade: [0.05, '#000']
                        });
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                });
            });
        }

    </script>

@endsection